
#include "bbSQLiteStorage.h"

// Mozilla imports.
#include <nsCOMPtr.h>
#include <nsICategoryManager.h>
#include <nsIComponentManager.h>
#include <nsIGenericFactory.h>
#include <nsServiceManagerUtils.h>

NS_GENERIC_FACTORY_CONSTRUCTOR(bbSQLiteStorage);

NS_METHOD
bbSQLiteStorageRegisterSelf(nsIComponentManager* aCompMgr,
                    nsIFile* aPath,
                    const char* registryLocation,
                    const char* componentType,
                    const nsModuleComponentInfo* info)
{
  nsresult rv;
  nsCOMPtr<nsICategoryManager> catMan =
      do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
  NS_ENSURE_SUCCESS(rv, rv);

  rv = catMan->AddCategoryEntry("balancebook-storage",
                                BB_SQLITESTORAGE_CLASSNAME,
                                BB_SQLITESTORAGE_CONTRACTID,
                                PR_TRUE, PR_TRUE,
                                nsnull);
  NS_ENSURE_SUCCESS(rv, rv);

  return NS_OK;
}

NS_METHOD
bbSQLiteStorageUnregisterSelf(nsIComponentManager* aCompMgr,
                      nsIFile* aPath,
                      const char* registryLocation,
                      const nsModuleComponentInfo* info)
{
  nsresult rv;
  nsCOMPtr<nsICategoryManager> catMan =
      do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
  NS_ENSURE_SUCCESS(rv, rv);

  rv = catMan->DeleteCategoryEntry("balancebook-storage",
                                   BB_SQLITESTORAGE_CLASSNAME,
                                   PR_FALSE);
  NS_ENSURE_SUCCESS(rv, rv);

  return NS_OK;
}

static nsModuleComponentInfo components[] =
{
  {
    BB_SQLITESTORAGE_CLASSNAME,
    BB_SQLITESTORAGE_CID,
    BB_SQLITESTORAGE_CONTRACTID,
    bbSQLiteStorageConstructor,
    bbSQLiteStorageRegisterSelf,
    bbSQLiteStorageUnregisterSelf
  }};

NS_IMPL_NSGETMODULE(bbSQLiteStorageModule, components)
